package com.allwees.bs.module.fms.util;

import com.allwees.bs.module.fms.entity.BaseAccount;
import com.allwees.sender.sms.SmsCodeVerifier;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.PostConstruct;

@Component
public class WithdrawPasswordVerifier {
//	@Value("${fms.withdraw.privateKey|}")
	private String withdrawPrivateKey;

	@Autowired
	private PasswordEncoder passwordEncoder;

	private static String staticWithdrawPrivateKey;

	private static PasswordEncoder staticPasswordEncoder;

	@PostConstruct
	private void init() {
		staticWithdrawPrivateKey = withdrawPrivateKey;
		staticPasswordEncoder = passwordEncoder;
	}

	public static void verifyPassword(BaseAccount account, String ecryptPassword) {
		if(ArrayUtils.contains(SmsCodeVerifier.MOCK_MOBILES, account.getMobile())) {
			//TODO
			return;
		}
		// TODO: RSA未加密
		Assert.isTrue(account.getWithdrawPassword().equals(ecryptPassword),"提现密码不正确");

		// TODO: RSA 加密
//		RSA rsa = new RSA(staticWithdrawPrivateKey, null);
//		String password = new String(rsa.decrypt(ecryptPassword, KeyType.PrivateKey));
//		account.verifyWithdrawPassword(staticPasswordEncoder, password);
	}
}
